<?php if (!defined('TL_ROOT')) die('You can not access this file directly!');

/**
 * TYPOlight webCMS
 *
 * The TYPOlight webCMS is an accessible web content management system that 
 * specializes in accessibility and generates W3C-compliant HTML code. It 
 * provides a wide range of functionality to develop professional websites 
 * including a built-in search engine, form generator, file and user manager, 
 * CSS engine, multi-language support and many more. For more information and 
 * additional TYPOlight applications like the TYPOlight MVC Framework please 
 * visit the project website http://www.typolight.org.
 *
 * This is the data container array for table tl_catalog_types.
 *
 * PHP version 5
 * @copyright  Thyon Design 2008 
 * @author     John Brand <john.brand@thyon.com>
 * @package    CatalogExt
 * @license    GPL 
 * @filesource
 */


/**
 * Table tl_catalog_types 
 */

// RSS Feed Generator
/*
	$GLOBALS['TL_DCA']['tl_catalog_types']['config']['onload_callback'][] = 
            array('CatalogExt', 'generateFeeds');
*/


// Palettes
$GLOBALS['TL_DCA']['tl_catalog_types']['palettes']['default'] 
= $GLOBALS['TL_DCA']['tl_catalog_types']['palettes']['default'] . ';jumpTo,aliasField;searchable';

// Subpalettes 
$GLOBALS['TL_DCA']['tl_catalog_types']['palettes']['__selector__'][] = 'searchable';
array_insert($GLOBALS['TL_DCA']['tl_catalog_types']['subpalettes'], 1, array
	(
		'searchable'     => 'searchCondition,titleField'
	)
);




$GLOBALS['TL_DCA']['tl_catalog_types']['fields']['jumpTo'] =	array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_catalog_types']['jumpTo'],
	'exclude'                 => true,
	'inputType'               => 'pageTree',
	'eval'                    => array('fieldType'=>'radio', 'helpwizard'=>true),
	'explanation'             => 'jumpTo',
	'doNotCopy'               => true,
);

$GLOBALS['TL_DCA']['tl_catalog_types']['fields']['searchable'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_catalog_types']['searchable'],
	'exclude'                 => true,
	'inputType'               => 'checkbox',
	'eval'										=> array('submitOnChange'=>true),
	'doNotCopy'               => true,
);

$GLOBALS['TL_DCA']['tl_catalog_types']['fields']['searchCondition'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_catalog_types']['searchCondition'],
	'exclude'                 => true,
	'inputType'               => 'text',
	'eval'                    => array('decodeEntities'=>true),
	'doNotCopy'               => true,
);

$GLOBALS['TL_DCA']['tl_catalog_types']['fields']['titleField'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_catalog_types']['titleField'],
	'exclude'                 => true,
	'inputType'               => 'select',
	'options_callback'        => array('tl_catalog_types_ext', 'getTitleFields'),
	'eval'                    => array('mandatory' => false, 'includeBlankOption' => true),
	'doNotCopy'               => true,
);

$GLOBALS['TL_DCA']['tl_catalog_types']['fields']['aliasField'] = array
(
	'label'                   => &$GLOBALS['TL_LANG']['tl_catalog_types']['aliasField'],
	'exclude'                 => true,
	'inputType'               => 'select',
	'options_callback'        => array('tl_catalog_types_ext', 'getAliasFields'),
	'eval'                    => array('mandatory' => false, 'includeBlankOption' => true),
	'doNotCopy'               => true,
);


class tl_catalog_types_ext extends tl_catalog_types
{

	public function getAliasFields(DataContainer $dc)
	{

		$objFields = $this->Database->prepare("SELECT name, colName FROM tl_catalog_fields WHERE pid=? AND type=?")
				->execute($dc->id, 'alias');

		 
		$result = array();
		while ($objFields->next())
		{
			$result[$objFields->colName] = $objFields->name;
		}
		
		return $result;
	}

	public function getTitleFields(DataContainer $dc)
	{

		$objFields = $this->Database->prepare("SELECT name, colName FROM tl_catalog_fields WHERE pid=? AND type=? AND titleField=?")
				->execute($dc->id, 'text', 1);
		 
		$result = array();
		while ($objFields->next())
		{
			$result[$objFields->colName] = $objFields->name;
		}
		
		return $result;
	}

}



?>